package cn.longge.mapper;

import org.springframework.util.StringUtils;

import java.util.Map;

public class ExamineSqlProvider {

    public String selectByCondition(Map<String,Object> params){
        StringBuilder sb = new StringBuilder();
        sb.append("select ex.id,so.name as office_name,su.name as user_name,ex.type,ex.score,ex.create_date \n" +
                "from examine ex,sys_user su,sys_office so \n" +
                "where ex.del_flag = 0 \n" +
                "and ex.examine_user_id = su.id \n" +
                "and su.office_id = so.id \n" +
                "and su.del_flag = 0 \n" +
                "and so.del_flag = 0");
        if(params.containsKey("officeId") && !StringUtils.isEmpty(params.get("officeId"))){
            sb.append(" and so.id = #{officeId} ");
        }
        if(params.containsKey("userName") && !StringUtils.isEmpty(params.get("userName"))){
            sb.append(" and su.name like concat('%',#{userName},'%') ");
        }
        if(params.containsKey("type") && !StringUtils.isEmpty(params.get("type"))){
            sb.append(" and ex.type = #{type} ");
        }
        return sb.toString();
    }
}
